package com.ozo.cloud.gen.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ozo.cloud.common.base.model.ResultVO;
import com.ozo.cloud.common.log.annotation.OperateLog;
import com.ozo.cloud.gen.entity.GenProject;
import com.ozo.cloud.gen.pojo.dto.GenProjectSaveDTO;
import com.ozo.cloud.gen.service.IGenProjectService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 项目配置 前端控制器
 * </p>
 *
 * @author qiangesoft
 * @since 2024-11-12
 */
@Tag(name = "项目配置管理")
@RequiredArgsConstructor
@RestController
@RequestMapping("/project")
public class GenProjectController {

    private final IGenProjectService genProjectService;

    @OperateLog(value = "添加项目配置", module = "项目配置")
    @SaCheckPermission("gen:project:add")
    @Operation(summary = "添加项目配置")
    @PostMapping("/add")
    public ResultVO<Void> add(@RequestBody @Valid GenProjectSaveDTO saveDTO) {
        genProjectService.add(saveDTO);
        return ResultVO.success();
    }

    @OperateLog(value = "编辑项目配置", module = "项目配置")
    @SaCheckPermission("gen:project:edit")
    @Operation(summary = "编辑项目配置")
    @PutMapping("/edit")
    public ResultVO<Void> edit(@RequestBody @Valid GenProjectSaveDTO saveDTO) {
        genProjectService.edit(saveDTO);
        return ResultVO.success();
    }

    @Operation(summary = "项目配置")
    @GetMapping("/get")
    public ResultVO<GenProject> get() {
        return ResultVO.success(genProjectService.get());
    }

}
